from flask import Flask, request, render_template, session


app = Flask(__name__)
app.secret_key = 'your_secret_key_here'  # 设置一个安全的密钥


@app.route('/')
def hello_world():
    return render_template("index.html")


@app.route("/To_java_class", methods=["POST"])
def index_handle():
    # 从表单获取数据并保存到会话
    subject = request.form["subject"]
    exam_time_minutes = int(request.form["examTime"])  # 确保转换为整数
    teacher_message = request.form["teacherMessage"]
    exam_start_time_str = request.form["examStartTime"]

    session["subject"] = subject
    session["examTime"] = exam_time_minutes
    session["teacherMessage"] = teacher_message
    session["examStartTime"] = exam_start_time_str

    print(session.get("subject"))
    # 重定向到另一个页面或返回相同的页面，这里以返回为例
    return render_template("general.html", session=session)


"""主运行模块"""
if __name__ == '__main__':  # 确保此模块被导入时，不会被运行
    app.run(host="0.0.0.0", port=5000)
